home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1999 / MacHack 1999.toast / The Hacks / NetPokerForMacOSX_Server / HoldEmHigh / PotManager.m < prev   
Encoding:
Text File  |  1999-06-25  |  1.0 KB  |  44 lines

  1. #import "PotManager.h"
  2.  
  3. @implementation PotManager
  4.  
  5. #define COIN_STEP   5.0
  6.  
  7. - (NSImage *)imageWithNumberCoins:(int)numCoins
  8. {
  9.    NSRect r =  [potImage frame];
  10.    NSImage *scratchImage = [[[NSImage allocWithZone:NULL] initWithSize:r.size]autorelease];
  11.    NSImage *coin = [NSImage imageNamed:@"Coin"];
  12.    unsigned i;
  13.  
  14. // lock focus on the destination image:
  15.    [scratchImage lockFocus];
  16.  
  17. // set the color to transparent and fill it:
  18.    [[NSColor clearColor] set];
  19.    NSRectFill(NSMakeRect(0.0,0.0,r.size.width,r.size.height));
  20.  
  21. // step through and make that many coins:
  22.    for (i = 0; i < numCoins; i++) {
  23.         NSPoint origin = NSMakePoint(0.0,i*COIN_STEP);
  24.         [coin compositeToPoint:origin operation:NSCompositeSourceOver];
  25.    }
  26.  
  27. // NEVER forget to unlock focus!
  28.    [scratchImage unlockFocus];
  29.    return scratchImage;
  30. }
  31.  
  32. - (void)updatePotAmount:(int)amount
  33. {
  34.     pot = amount;
  35.     [potImage setImage:[self imageWithNumberCoins:rint(amount/100.0)]];
  36.     [potField setStringValue:[NSString stringWithFormat:@"$ %d",amount]];
  37. }
  38.  
  39. - (int)pot {
  40.    return pot;
  41. }
  42.  
  43. @end
  44.